/**Hystrix+Eureka+Ribbon+RestTemplate
 * 1）依赖库：SpringCloud版本为Hoxton及以下，核心依赖为spring-cloud-starter-netflix-hystrix和spring-cloud-starter-netflix-eureka-client（含ribbon）
 * 2）main上@EnableHystrix 注解之
 * 3）调用服务的controller（MyWebClient）方法上 @HystrixCommand(fallbackMethod="myFallBackRibbon")注解之
 * 4）实现降级方法myFallBackRibbon，参数和返回值与被注解的方法要完全一致，从而实现被注解方法调用的服务故障时的熔断、降级和隔离
 * 5）Hystrix属性可以在注解上配置，也可以在配置文件（yml）中配置。重试主要是Ribbon的属性，限流则通过配置Hystrix的threadpool的相关属性来实现
 */
package com.example.demohystrixribbonconsumer;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.context.annotation.Bean;
import org.springframework.web.client.RestTemplate;

@SpringBootApplication
@EnableDiscoveryClient
@EnableHystrix            //启用断路器必须使用该注解(@EnableCircuitBreaker与之等效)
@EnableHystrixDashboard   //启用Hystrix可视化监控(仪表盘)
public class DemoHystrixRibbonConsumerApplication {

    public static void main(String[] args) {
        SpringApplication.run(DemoHystrixRibbonConsumerApplication.class, args);
    }

    @Bean
    @LoadBalanced
    public RestTemplate restTemplate() {
        return new RestTemplate();
    }

}
